import { join } from 'path';
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { AuthorsModule } from './modules/authors.module';
import { PostsModule } from './modules/posts.module';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { AppController } from './app.controller';
import { UpperCaseDirective } from './common/directives/upper-case.directive';
import { AuthDirective } from './common/directives/auth.directive';

@Module({
  imports: [
    AuthModule, UsersModule,
    AuthorsModule, PostsModule,
    GraphQLModule.forRoot({
      installSubscriptionHandlers: true,
      autoSchemaFile: join(process.cwd(), 'src/schema.gql'),
      context: ({ req }) => ({ req }),
      schemaDirectives: {
        auth: AuthDirective,
        authorized: AuthDirective,
        authenticated: AuthDirective,
        upper: UpperCaseDirective,
        upperCase: UpperCaseDirective,
      },
    }),
  ],
  controllers: [AppController],
})
export class AppModule { }

/*
import { AuthDirective } from './common/directives/auth.directive';
import { UpperCaseDirective } from './common/directives/upper-case.directive';
import { GraphQLDirective } from 'graphql';
      schemaDirectives: {
        auth: AuthDirective,
        authorized: AuthDirective,
        authenticated: AuthDirective,
        upper: UpperCaseDirective,
        upperCase: UpperCaseDirective,
      },
      buildSchemaOptions: {
        directives: [
          new GraphQLDirective({
            name: 'upper',
            description: 'upper case for field',
            locations: ['FIELD_DEFINITION'],
            extensions: {
              upper: UpperCaseDirective,
              upperCase: UpperCaseDirective,
            }
          }),
        ]
      }
*/
